from __future__ import division
import logging

from allennlp.common.params import Params
from allennlp.commands.train import train_model_from_file
from allennlp.commands.evaluate import *
import argparse
import os

parser = argparse.ArgumentParser(description='PyTorch SQuAD')

parser.add_argument('--config', required=True, type=str, metavar='N',
                    help='configuration of model file')
parser.add_argument('--save_dir', default='model', type=str, metavar='N',
                    help='directory to save model file')

class AverageMeter(object):
    """Computes and stores the average and current value"""
    def __init__(self):
        self.reset()

    def reset(self):
        self.val = 0
        self.avg = 0
        self.sum = 0
        self.count = 0

    def update(self, val, n=1):
        self.val = val
        self.sum += val * n
        self.count += n
        self.avg = self.sum / self.count

def makedirs(dirs):
    for dir in dirs:
        os.makedirs(dir, exist_ok=True)

def main():
    args = parser.parse_args()
    assert os.path.exists(args.config)
    train_model_from_file(args.config, args.save_dir, file_friendly_logging=False)
if __name__ == '__main__':
    main()
    print('done')
